package deom1;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class MyCardGame {
    /*
    * 定义花色的种类
    * */
    public String[] SUIT = {"♥","♣","♦","♠"};

    /*
    * 创建一副牌
    * */
    public List<MyCard> createCard() {
        List<MyCard> list = new ArrayList<>(51);
        for (int i = 1; i <= 13; i++) {
            for (int j = 0; j < SUIT.length; j++) {
                MyCard myCard = new MyCard();
                myCard.design = SUIT[j];
                myCard.value = i;
                list.add(myCard);
            }
        }
        return list;
    }

    /*
    * 洗牌
    * */
    public void shuffleCard(List<MyCard> list) {
        Random random = new Random();
        for (int i = list.size() - 1; i >= 0; i--) {
            int ranCount = random.nextInt(52);
            swap(list,i,ranCount);
        }
    }

    /*
    * 交换
    * */
    public void swap(List<MyCard> list,int i,int ranCount) {
        MyCard ret = list.get(i);
        list.set(i,list.get(ranCount));
        list.set(ranCount,ret);
    }

}
